-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
54 lines (45 loc) · 952 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
int comparador(const void *a, const void *b);
int comparadorReverso(const void *a, const void *b);
int main()
{
int vezes, N, i, tamP = 0, tamI = 0, aux, Trocou;
int *vP = NULL, *vI = NULL;
cin >> vezes;
for (i = 0; i < vezes; i++)
{
cin >> N;
if (N % 2 == 0)
{
tamP++;
vP = (int *)realloc(vP, sizeof(int) * tamP);
vP[tamP - 1] = N;
}
else
{
tamI++;
vI = (int *)realloc(vI, sizeof(int) * tamI);
vI[tamI - 1] = N;
}
}
qsort(vP, tamP, sizeof(int), comparador);
qsort(vI, tamI, sizeof(int), comparadorReverso);
for (i = 0; i < tamP; i++)
{
cout << vP[i] << endl;
}
for (i = 0; i < tamI; i++)
{
cout << vI[i] << endl;
}
return 0;
}
int comparador(const void *a, const void *b)
{
return (*(int *)a - *(int *)b);
}
int comparadorReverso(const void *a, const void *b)
{
return (*(int *)b - *(int *)a);
}